package com.liusy.code.actions;

import java.io.File;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

import com.liusy.code.wizards.CodeGenerationWizard;

/**
 * 打开资源管理器
 * @author liusy
 *
 */
@SuppressWarnings("restriction")
public class OpenExplorerAction implements IWorkbenchWindowActionDelegate
{
	private Shell shell;
	private IStructuredSelection selection;

	@Override
	public void run(IAction action)
	{
		//打开向导对话框
		CodeGenerationWizard wizard = new CodeGenerationWizard();
		wizard.init(null, selection);
		WizardDialog dialog = new WizardDialog(this.shell, wizard);
		dialog.open();
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection)
	{
		//this.selection = (IStructuredSelection)selection;
	}

	protected File getJarFile(IAdaptable adaptable)
	{
		JarPackageFragmentRoot jpfr = (JarPackageFragmentRoot) adaptable;
		File selected = jpfr.getPath().makeAbsolute().toFile();
		if (!(selected.exists()))
		{
			File projectFile = new File(jpfr.getJavaProject().getProject().getLocation().toOSString());
			selected = new File(projectFile.getParent() + selected.toString());
		}
		return selected;
	}

	@Override
	public void dispose()
	{
	}
	@Override
	public void init(IWorkbenchWindow arg0) {
		// TODO Auto-generated method stub
		
	}

}